<template>
	<view>
<!-- 		<text>输入用户名</text>
		<input type="text" class="userInfo" v-model.trim="value" @blur="intoChat" /> -->
	</view>

</template>

<script>
	
		
	export default {
		data() {
			return {
				value: '',
				token: '初始值',
				authFlag: true
			};
		},
		onLoad(params){
			if(Object.keys(params).length){
			  uni.navigateTo({
			  	url: `../HM-chat/HM-chat`
			  });	
			}else{
			  uni.navigateBack({
			      delta: 2
			  });	
			}
		
			 // let tikect = ''
			 // if(params.ticket === undefined || params.ticket === 'undefined' || params.ticket === null || params.ticket === 'null'){
				//   tikect = ''
			 // }else{
				//   tikect = params.ticket
			 // }
			 // sessionStorage.setItem('ticket', tikect);
		}, 
		mounted() {
			// this.$nextTick(()=>{
			// 	this.getToken()
			// 	// this.getTicket()
			// })
			
		},
		methods: {
			intoChat() {
				if (!this.value) {
					return
				}
				uni.navigateTo({
					url: `../HM-chat/HM-chat`
				});
			},
			getToken() {
				if (window.KDS_Native) {
					// 进入页面获取token
					let token = '';
					window.getNewToken = (tk) => {
						token = tk;
					};
					var timer2 = setInterval(() => {
						if (token != '') {
							console.log('token', token)
							 sessionStorage.setItem('token', token);
							clearInterval(timer2);
						}
						if (window.KDS_Native.getNewLoginAuthToken) {
							console.log('getNewLoginAuthToken', token)
							window.KDS_Native.getNewLoginAuthToken(true, 'getNewToken');
						} else if (window.KDS_Native.getTokenWxApiNew) {
							console.log('getTokenWxApiNew', token)
							window.KDS_Native.getTokenWxApiNew(true, 'getNewToken');
						}
					}, 20);
				}
			},
			getTicket() {
				let ticket = sessionStorage.getItem('ticket')
				// app内调用原生登录，
				const timer = setInterval(() => {
					if (!ticket) {
						if (window.KDS_Native && window.KDS_Native.getTradeAuth) {
							window.KDS_Native.getTradeAuth();
						}
					} else {
						clearInterval(timer);
					}
				}, 500);
				// 准备给app的回调函数，注册到全局window上
				window.setTradeAuth = (tick) => {
					ticket = tick || '';
					if (tick == 'undefined' || tick == 'null') {
						ticket = '';
					}
					if (ticket) {
						console.log('ticket', ticket)
						sessionStorage.setItem('ticket', ticket);
					     window.location.reload()
					}
				};
				window.getTradeAuthCallback = () => {
					this.authFlag = false;
				};
			},
			
		}
	}
</script>

<style lang="scss">
	.userInfo {
		background-color: #f0f0f0;
	}
</style>
